package com.lzh.oss.controller;

import com.lzh.commonutils.CommonResult;
import com.lzh.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author lzhstart
 * @create 2021/4/22 16:14
 */
@CrossOrigin
@RestController
@RequestMapping("/eduOss")
public class FileController {

    @Autowired
    private FileService fileService;

    @ApiOperation(value = "上传头像")
    @PostMapping("/upload")
    public CommonResult uploadAvatar(MultipartFile file) {
        String avatar = fileService.uploadAvatar(file);
        return CommonResult.ok().data("url", avatar);
    }

    @ApiOperation(value = "删除头像")
    @DeleteMapping("/delete")
    public CommonResult deleteAvatar(@RequestParam String filePath) {
        fileService.deleteAvatar(filePath);
        return CommonResult.ok();
    }
}
